<template>
	<view>
		<image class="img" :src="list.cover_img"></image>
		<view class="gname">{{list.gname}}</view>
		<view class="gname">{{list.descr}}</view>
		<view class="descr">￥{{list.descr}}</view>
		<view class="bottom">
			<view class="bottom1"><image src="../../../static/icons/kf.png"></image></view>
			<view class="bottom2" @tap="add">加入购物车</view>
			<view class="bottom3">立即购买</view>
		</view>
		<view class="cover" v-if="yc">
			<view class="cover1">
				<image class="cover2" :src="list.cover_img"></image>
				<view class="cover3">{{list.gname}}</view>
				<view class="cover4">库存数量:</view>
				<view class="cover5">颜色分类</view>
				<view class="cover6">
					特色服务
					<view class="cover61">送货上门</view>
					<view class="cover61">上门安装</view>
				</view>
				<view class="cover7">
					<view class="cover71">购买数量</view>
					<view class="cover71">
						<view class="cover72" @tap='reduce'>-</view>
						<input class="cover72" type="text" v-model="num1">
						<view class="cover72" @tap='adds'>+</view>
					</view>
				</view>
				<view class="cover8" @tap="addCart">确定</view>
				
			</view>
		</view>
	  
	</view>
</template>

<script>
	import {detail,addcart} from '../../../util/home/index.js'
	export default {
		data() {
			return {
				autoplay: true,
				interval: 2000,
				list:'',
				yc:false,
				num1:1
			}
		},
		methods:{
			add(){
				if(uni.getStorageSync('userInfo')){
					this.yc=!this.yc
				}else{
					uni.navigateTo({
						url:'/pages/user/login/login'
					})
					uni.showToast({
						title:'请登录'
					})
				}
				
			},
			addCart(){
				if(uni.getStorageSync('cartList')){
					var cartList=uni.getStorageSync('cartList');
					
					var index=cartList.findIndex(item=>
						item.id==this.list.id
					)
					console.log(index)
					if(index==-1){
						this.list.num=this.num1;
					    cartList.push(this.list);
						uni.setStorageSync('cartList',cartList)
					}else{
						cartList[index].num+=this.num1;
						uni.setStorageSync('cartList',cartList)
					}
					
					// uni.setStorageSync('cartList',cartList)
				}else{
					var cartList=[];
					this.list.num=this.num1;
					cartList.push(this.list);
					uni.setStorageSync('cartList',cartList)
				}	
			},
			reduce(){
				if(this.num1>1){
					this.num1--
				}
			},
			adds(){
				if(this.num1<this.list.skuList[0].count){
					this.num1++
				}else{
					uni.showToast({
						title:'没货了'
					})
				}
			}
		},
		onLoad(val){
			console.log(val)
			detail({
				id:val.id
			})
			.then(res=>{
				console.log(res.data.data)
				 this.list=res.data.data;
			})
		}
		
	}
</script>

<style>
	.img{
		width: 100%;
		height: 634rpx;
	}
	.gname{
		width: 614rpx;
		height: 42rpx;
		margin:10px auto
	}
	.descr{
		width: 614rpx;
		height: 42rpx;
		margin:50px auto
	}
	.bottom{
		position: fixed;
		bottom: 0;
		width: 750rpx;
		height: 120rpx;
		display: flex;
		justify-content: start;
		background-color: white;
	}
	.bottom view{
		margin-top: 20rpx;
	}
	.bottom1{
		width: 238rpx;
		height: 80rpx;
		text-align: center;
	}
	.bottom1 image{
		width: 54rpx;
		height: 54rpx;
	}
	.bottom2{
		width: 238rpx;
		height: 80rpx;
		background-color: #E2E2E2;
		color: grey;
		text-align: center;
		line-height: 40px;
	}
	.bottom3{
		width: 238rpx;
		height: 80rpx;
		background-color: #354E44;
		color: white;
		text-align: center;
		line-height: 40px;
	}
	.cover{
		position: fixed;
		top: 80rpx;
		left: 0;
		width: 750rpx;
		height: 1140rpx;
		background-color: rgba(0,0,0,0.6);
		z-index: 999;
	}
	.cover1{
		position: fixed;
		left: 75rpx;
		top: 200rpx;
		width: 600rpx;
		height: 750rpx;
		background-color: white;
	    border-radius: 15px;
	}
	.cover2{
		position: relative;
		top: -60rpx;
		left: 60rpx;
		width: 200rpx;
		height: 200rpx;
		border-radius: 15px;
	}
	.cover3{
		margin-left: 300rpx;
		margin-top: -150rpx;
	}
	.cover4{
		margin-left: 300rpx;
		font-size: 12px;
		color: grey;
	}
	.cover5{
		margin-left: 100rpx;
		margin-top: 60rpx;
		font-weight: 900;
	}
	.cover6{
		margin-left: 100rpx;
		margin-top: 10rpx;
		font-weight: 900;
	}
	.cover61{
		width: 400rpx;
		height: 40rpx;
		background-color: grey;
		border-radius: 5px;
		margin-left: 10rpx;
		margin-top: 10rpx;
	}
	.cover7{
		margin-top: 10px;
		margin-left: 100rpx;
	}
	.cover71{
		float: left;
	}
	.cover71:nth-child(2){
		margin-left: 30rpx;
	}
	.cover72{
		width: 60rpx;
		float: left;
		text-align: center;
		border-radius: 50%;
		background-color: #F1ECE7;
	}
	.cover8{
		margin-top: 60rpx;
		margin-left: 100rpx;
		width: 100rpx;
		height: 60rpx;
		background-color: #354E44;
		color: white;
		text-align: center;
		line-height: 60rpx;
	}
</style>
